package com.spc.car.data.domain.htgg.po;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.spc.car.common.utils.StringUtils;
import com.spc.car.data.entity.project.ProjectHtggPublish;
import com.spc.car.data.util.PageParam;
import lombok.Data;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.Pattern;
import java.util.Date;

@Data
public class HtggPublishPO<T> extends PageParam<T> {

    private String contractName;
    private String ProjName;

    private String bidIndustrCode;

    @Pattern(regexp = "[0-9]{6}", message = "请输入六位的区域编码")
    private String zoneId;

    @Pattern(regexp = "A|N|P", message = "请输入正确的类型")
    private String publishStatus;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date beginTime;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date endTime;

    /**构造查询*/
    public Wrapper towWrapper() {
        LambdaQueryWrapper<ProjectHtggPublish> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(contractName), ProjectHtggPublish::getContractName, this.contractName)
                .like(StringUtils.isNotBlank(this.ProjName), ProjectHtggPublish::getProjName, this.ProjName)
                .eq(StringUtils.isNotBlank(this.zoneId), ProjectHtggPublish::getZoneId, this.zoneId)
                .eq(StringUtils.isNotBlank(this.bidIndustrCode), ProjectHtggPublish::getBidIndustryCode, this.bidIndustrCode)
                .ge(ObjectUtils.isNotEmpty(beginTime), ProjectHtggPublish::getPublishDate, this.beginTime)
                .le(ObjectUtils.isNotEmpty(endTime), ProjectHtggPublish::getPublishDate, this.endTime);
        return wrapper;
    }
}
